package UserInterface;

import InterfacesAndModules.DataOperationInterface;
import InterfacesAndModules.UsefulTools;
import NewAirportInfo.AirportBasicInfo;
import NewAirportInfo.AirportRunwayInfo;

import java.util.ArrayList;
import java.util.Scanner;

public class InitializeAirportInfo {
    public final void InitializeAirport(ArrayList<AirportBasicInfo> PassIn) {
        //声明临时变量
        String ThisAirportName;//机场名
        String ThisAirportIATA;//机场三字IATA
        String ThisAirportICAO;//机场四字ICAO
        float AirportAlt;//机场标高
        int Runways;//机场有多少条跑道
        //开始用户接口
        Scanner UserInput = new Scanner(System.in);
        System.out.println("请输入机场四字ICAO");
        ThisAirportICAO = UserInput.nextLine();
        System.out.println("请输入机场三字IATA");
        ThisAirportIATA = UserInput.nextLine();
        System.out.println("请输入机场名");
        ThisAirportName = UserInput.nextLine();
        System.out.println("请输入机场在标准气压下的高度，单位:英尺(FT)");
        AirportAlt = UserInput.nextFloat();
        System.out.println("请输入机场跑道数量，一条跑道算两个，例如18-36跑道算两个");
        Runways = UserInput.nextInt();



        /*跑道信息，使用表格化一览*/
        ArrayList<AirportRunwayInfo> ARI = new ArrayList<>(Runways);
        String UserInputIsSure;
        UserInputIsSure IsSure = new UserInputIsSure();
        int isSure;
        /*跑道信息初始化*/
        for (int Counter = 0; Counter < Runways; Counter++) {
            System.out.println("请输入跑道名称，名称和跑道ID绑定，您可以按照本机场手册输入");
            System.out.println("一般是 1: 36R，后面 2:18L，类似的去绑定");
            System.out.println("跑道ID " + Counter + " :");
            UserInput.nextLine();//清掉输入区缓存
            AirportRunwayInfo Temp = new AirportRunwayInfo(UserInput.nextLine());
            System.out.println("跑道的航向绑定，例如 36R CRS: 359");
            Temp.RunwayCRS = UserInput.nextInt();
            System.out.println("跑道 " + Temp.RunwayName + "是否配备ILS系统 y/n");
            UserInput.nextLine();//清掉输入区缓存
            UserInputIsSure = UserInput.nextLine();
            isSure = IsSure.YNIsSure(UserInputIsSure);
            if (isSure == 1) {
                System.out.println("跑道 " + Temp.RunwayName + "不配备ILS");
            } else if (isSure == -1) {
                System.out.println("System Error");
                System.exit(-1);
            } else if (isSure == 0) {
                Temp.IsRunwayHaveILS = true;
                System.out.println("请填写ILS名称，例如36R ILS名称: IQU");
                Temp.RunwayILSName = UserInput.nextLine();
                System.out.println("请填写跑道ILS频率，例如108.80");
                System.out.println("跑道 " + Temp.RunwayName + "ILS频率:");
                Temp.RunwayILSFreq = UserInput.nextFloat();
                UserInputIsSure = UserInput.nextLine();
                System.out.println("请填写跑道ILS声音");
                System.out.println(".为短响，-为长响，一般七响，例如 ..--..---");
                Temp.RunwayILSVoice = UserInput.nextLine();
                System.out.println("ILS盲降等级，一般为 I,II,III-A/B/C");
                System.out.println("可输入1/2/3/4/5 来确认跑道ILS等级");
                Temp.RunwayILS_CAT = UserInput.nextInt();
                Temp.RunwayILS_CAT = IsSure.UsingCorrectNumInputIsCorrect(1, 5, Temp.RunwayILS_CAT);
            }
            ARI.add(Temp);
        }
        /*准备初始化*/
        DataOperationInterface Doi = new DataOperationInterface();
        System.out.println("请确认以下信息，如果确认，将会初始化此程序");
        System.out.println("机场名: " + ThisAirportName);
        System.out.println("ICAO/IATA: " + ThisAirportICAO + "/" + ThisAirportIATA);
        System.out.println("机场标高: " + AirportAlt);
        System.out.println("机场跑道数量: " + Runways);
        System.out.println("机场物理跑道信息:");
        System.out.println("各个跑道信息");
        System.out.println("******************************");
        for (int Counter = 0; Counter < Runways; Counter++) {
            AirportRunwayInfo Temp = Doi.GetAirportRunwayInfo(ARI, Counter);
            System.out.println("跑道名: " + Temp.RunwayName + "系统为此跑道分配的ID " + Counter);
            if (!Temp.IsRunwayHaveILS) {
                System.out.println("该跑道无ILS，航向信息" + Temp.RunwayCRS);
            } else if (Temp.IsRunwayHaveILS) {
                System.out.println("跑道ILS名称 " + Temp.RunwayILSName + " 跑道ILS频率 " + Temp.RunwayILSFreq);
                System.out.println("跑道航向 " + Temp.RunwayCRS + " 跑道ILS声纹 " + Temp.RunwayILSVoice);
                UsefulTools Tools = new UsefulTools();
                System.out.println("跑道ILS等级: " + Tools.ILSCATInfo(Temp.RunwayILS_CAT));
            }
            Temp.IsRunwayOpen = true;
            System.out.println("******************************");
        }
        System.out.println("******************************");
        System.out.println("是否确认信息 y/n");
        UserInputIsSure = UserInput.nextLine();
        isSure = IsSure.YNIsSure(UserInputIsSure);
        if (isSure == 0) {
            System.out.println("正在初始化程序");
            AirportBasicInfo TempABInfo = new AirportBasicInfo();
            TempABInfo.IsAirportInitialize = true;
            TempABInfo.ThisAirportName = ThisAirportName;
            TempABInfo.ThisAirportICAO = ThisAirportICAO;
            TempABInfo.ThisAirportIATA = ThisAirportIATA;
            TempABInfo.AirportAlt = AirportAlt;
            TempABInfo.Runways = Runways;
            TempABInfo.RunwayList = ARI;
            PassIn.add(TempABInfo);
            System.out.println("机场信息初始化完毕！");
        } else if (isSure == 1) {
            System.out.println("初始化已被取消");
            System.exit(0);
        }
    }
}
